package com.ruoyi.community.controller.wxApi;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.community.domain.Visit;
import com.ruoyi.community.service.IVisitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 访客Controller
 *
 * @author wj
 * @date 2022-02-22
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/wx/community/visit")
@Api(tags = {"访客"})
public class WxVisitController extends BaseController
{
    @Autowired
    private IVisitService visitService;

    /**
     * 查询访客列表
     */
    @ApiOperation(value = "查询访客列表")
    @GetMapping("/list")
    public TableDataInfo list(Visit visit)
    {
        Visit visistDto=new Visit();
        visistDto.setVisitUserId(visit.getVisitUserId());
        startPage();
        List<Visit> list = visitService.selectVisitList(visistDto);
        if (ObjectUtils.isEmpty(list)){
            return getNoDataTable(list);
        }
        return getDataTable(list);
    }

    /**
     * 获取访客详细信息
     */
    @ApiOperation(value = "获取访客详细信息")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo( Long id)
    {
        return AjaxResult.success(visitService.selectVisitById(id));
    }

    /**
     * 新增访客
     */
    @ApiOperation(value = "新增访客")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Visit visit)
    {
        return toAjax(visitService.insertVisit(visit));
    }

    /**
     * 修改访客
     */
    @ApiOperation(value = "修改访客")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Visit visit)
    {
        return toAjax(visitService.updateVisit(visit));
    }

    /**
     * 删除访客
     */
    @ApiOperation(value = "删除访客")
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        Long[] ids= {id};
        return toAjax(visitService.updateVisitByIds(ids));
    }
}
